<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class RegistRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *判断用户是否有权限进行此请求。
     * @return bool
     */
    public function authorize()
    {
        //3.修改返回值
        //如果需要表单验证则需要将该方法的返回值改为TRUE
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            //4.编写验证规则
            //4.1 用户名，邮箱，密码不能为空
            //4.1 邮箱格式是否正确
            //4.3 密码，确认密码 位数不能超过6不能小于20；
           'name'=> 'required',
           'email' => 'required|email',
           'password' => 'required|between:6,20|confirmed',
           'password_confirmation' => 'required|between:6,20',

        ];
    }

    /**
     * 5.获取以定义的验证规则的错误消息
     */
    public function messages()
    {
        return [
            'name.required' => '用户名不能为空',
            'email.required' => '邮箱不能为空',
            'email.email' => '邮箱格式不正确',
            'email.unique' => '邮箱已存在',
            'password.required' => '密码不能为空',
            'password.between:6,20' => '密码必需在6~20位之间',
            'password.confirmed' => '两次密码不一致',
            'password_confirmation.required' => '确认密码不能为空',
            'password_confirmation.between:6,20' => '确认密码必需在6~20位之间',


        ];
    }


}
